
#include "Student.h"
#include <iomanip>
using namespace std;


istream & operator>>(istream & is, Courses & c)
{
    return is >> c.zh_ >> c.mt_ >> c.en_;
}

ostream & operator<<(ostream & os, const Courses & c)
{
    return os << setw(8) << c.zh_
        << setw(8) << c.mt_
        << setw(8) << c.zh_;
}

ifstream & operator>>(ifstream & ifs, Courses & c)
{
    ifs >> c.zh_ >> c.mt_ >> c.en_;
    return ifs;
}

ofstream & operator<<(ofstream & ofs, const Courses & c)
{
    ofs << c.zh_ << " " << c.mt_ << " " << c.en_;
    return ofs;
}


//////////////////////////////////////////////////////////////////////////
istream & operator>>(istream & is, Student & s)
{
    return is >> s.name_ >> s.gender_ >> s.scores_;
}

ostream & operator<<(ostream & os, const Student & s)
{
    return os << setw(12) << s.id_
        << setw(10) << s.name_
        << setw(8) << s.gender_
        << s.scores_;
}

ifstream & operator>>(ifstream & ifs, Student & s)
{
    ifs >> s.id_;
    unsigned int len = 0;

    ifs >> len;
    char *str = new char[len + 1];
    ifs.get(str, len+1);
    s.name_ = str;
    delete[] str;

    ifs >> len;
    str = new char[len + 1];
    ifs.get(str, len+1);
    s.gender_ = str;
    delete[] str;

    return ifs >> s.scores_;
}

ofstream & operator<<(ofstream & ofs, const Student & s)
{
    ofs << s.id_ << " "
        << s.name_.length() << s.name_ << " "
        << s.gender_.length() << s.gender_ << " "
        << s.scores_;

    return ofs;
}

